//
//  YXYMainController.swift
//  SinaWeibo
//
//  Created by 袁向阳 on 16/6/23.
//  Copyright © 2016年 YXY.cn. All rights reserved.
//

import UIKit

class YXYMainController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController(YXYHomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(YXYMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(YXYDiscoveryController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(YXYProfileController(), title: "我", imageName: "tabbar_profile")
        
        
        // 自定义tabBar
        let tabBar: YXYCustomTabBar = YXYCustomTabBar()
        setValue(tabBar, forKey: "tabBar")
        
        tabBar.closure = {
            print("点击了加号按钮")
            let nav = UINavigationController(rootViewController: YXYComposeController())
            self.presentViewController(nav, animated: true, completion: nil)
        }
        
    }
    
    
    func addChildViewController(childVC:YXYBaseTableController , title:String , imageName:String) {
        
        let nav = UINavigationController(rootViewController: childVC)
        childVC.tabBarItem.image = UIImage(named: imageName)
        childVC.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childVC.tabBarItem.title = title
        
        childVC.navigationItem.title = title
        
        super.addChildViewController(nav)
    }
    
    
}

// MARK: - tabBarController的代理方法
extension YXYMainController {
    
    override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        
        // tabBar出现波纹效果
//        let trasnsitation = CATransition()
//        trasnsitation.duration = 1.0
//        trasnsitation.type = "rippleEffect"
//        trasnsitation.subtype = kCATransitionFromRight
//        trasnsitation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
//        view.layer.addAnimation(trasnsitation, forKey: nil)
       
//        print(self.selectedIndex)
        
    }
}




